package com.example.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.app.MMFragment1;
import com.example.app.MyMission;
import com.example.app.R;
import com.example.app.data.MMissionBean;

import java.util.List;

public class MMAdapter extends BaseAdapter {

    private List<MMissionBean> data;
    private Context context;
    private int count;

    public MMAdapter(List<MMissionBean> data, Context context,int size) {
        this.data = data;
        this.context = context;
        this.count=size;
    }

    @Override
    public int getCount() {
        return count;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view==null)
        {
            viewHolder=new ViewHolder();
            view= LayoutInflater.from(context).inflate(R.layout.mm_mission_bar,viewGroup,false);
            viewHolder.missionName=view.findViewById(R.id.mm_missionName);
            viewHolder.missionPlace= view.findViewById(R.id.mm_missionPlace);
            viewHolder.securityLevel= view.findViewById(R.id.mm_securityLevel);
            viewHolder.checkProcess= view.findViewById(R.id.mm_checkProcess);
            viewHolder.p1=view.findViewById(R.id.mm_pass);
            viewHolder.p2=view.findViewById(R.id.mm_notPass);
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.missionName.setText("任务名称："+data.get(i).getMissionName());
        viewHolder.missionPlace.setText("业务场景："+data.get(i).getMissionPlace());
        viewHolder.securityLevel.setText("安全等级："+data.get(i).getSecureLevel());
        viewHolder.checkProcess.setText("检查进度："+data.get(i).getCheckSchedule());
        if(data.get(i).getIfPass()==1)
        {
            viewHolder.p1.setVisibility(View.VISIBLE);
            viewHolder.p2.setVisibility(View.INVISIBLE);
        }

        return view;
    }

    private final class ViewHolder{
        TextView missionName;
        TextView missionPlace;
        TextView securityLevel;
        TextView checkProcess;
        TextView p1;
        TextView p2;
    }
}
